# include <stdio.h>
# include <string.h>
# include "Header.h"
# include "DirectoryOps.h"
# include "NArrayTree.h"

int listFile(char *filePath, char *outputFile, struct VFS *header, struct NArray_node *NArrayRoot) { 
	int i, ret = 0;
	struct NArray_node *temp;
	char str[100];
	copyString(str, filePath);
	temp = searchNArrayNode(NArrayRoot, filePath);
	if(temp) {
		for (i = 0; i < MAX_FD_SIZE; i++) {
			if(!strcmp(header -> fd[i].filePath, str)) {
				if(!strcmp(header -> fd[i].fileType, "txt")) {
					ret = writeToFile(outputFile, header -> bl[i].data);
					if (ret == 0)
						ret = 1;
					else
						ret = 3;
				}
				else
					ret = 2;
			}
		}
	}
	return ret;
}

int exportFile(char *filePath, char *outputFile, struct VFS *header, struct NArray_node *NArrayRoot) { 
	int i, ret = 1;
	struct NArray_node *temp;
	char str[100];
	copyString(str, filePath);
	temp = searchNArrayNode(NArrayRoot, filePath);
	filePath = truncateLeft (filePath, 4);
	if(temp) {
		for (i = 0; i < MAX_FD_SIZE; i++) {
			if(!strcmp(header -> fd[i].filePath, str)) {
				if(header -> fd[i].fileType == NULL) {
					ret = writeToFile(outputFile, header -> bl[i].data);
					if (ret == 1)
						ret = 2;
					break;
				}
				else
					ret = 3;
			}
		}
	}
	else
		ret = 1;
	return ret;
}
